home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Converters / Convert_PICT / Source / CommentedPSCode / Patterns < prev    next >
Text File  |  1995-06-12  |  3KB  |  149 lines

  1. %BEGIN Patterns
  2.  
  3. % Copyright (C) 1993 David John Burrowes
  4. % Distributed under terms of GNU General Public License.
  5. % See COPYING.text in Convert PICT's CommentedPSCode for a copy
  6.  
  7. %%%%%%%%%%%%%
  8. %    Notes:
  9. %        qdpat is an 8 byte hex string, like <AA55AA55AA55AA55>
  10. %        clut-info is a hex string of RGB byte triples for color lookup
  11. %        pict2pat is either of:
  12. %            qdpat [r g b] 2
  13. %            qdpat num clut-info bitdepth left top width height
  14. %                destwidth destheight packedflag bitmap-string 1
  15. %        See the common routine usePattern for how much of this is used
  16. %%%%%%%%%%%%%
  17.  
  18.  
  19. %%%%%%%%%%%%%
  20. %    Name:    GetPatGrey
  21. %    Syntax:    qdpat GetPatGrey  num
  22. %    About:    Given a hex string representing 8 bytes of data, assume it is a
  23. %            quickdraw B&W pattern. Calculate what percentage of the pixels
  24. %            are black, and return the % grey
  25. %%%%%%%%%%%%%
  26. /GetPatGrey
  27. {
  28.     /QDpattern exch def
  29.     /darkness 0 def
  30.     %
  31.     %     for each byte of pattern, convert to value between 0 and 1 and sum
  32.     %    This is not completely accurate, but works well enough (it counts #'s, not bits)
  33.     %
  34.     0 1 7
  35.     {
  36.         /patByte exch def
  37.         /darkness
  38.             QDpattern patByte get
  39.             255 div darkness add
  40.         def
  41.     }
  42.     for
  43.     %
  44.     %    Compute the average shade and push
  45.     %
  46.     darkness 8 div
  47. }
  48. def
  49.  
  50. %%%%%%%%%%%%%
  51. %    Name:    FillQDPatDict
  52. %    Syntax:    qdpat 0 FillQDPatDict -
  53. %            pict2pat FillQDPatDict -
  54. %    About:    Store pattern info we are passed.  This assumes an appropriate
  55. %            dictionary has been opened and is on the stack.
  56. %%%%%%%%%%%%%
  57. /FillQDPatDict
  58. {
  59.     begin
  60.         /QDPatType exch def
  61.         QDPatType 0 eq
  62.         {
  63.             /QDPatData exch def
  64.             /QDPatGrey QDPatData GetPatGrey def
  65.         }
  66.         {
  67.             QDPatType 2 eq
  68.             {
  69.                 /QDColorValue exch def
  70.                 pop % B&W pattern not needed. color will suffice.
  71.             }
  72.             {
  73.                 /QDPatBitmap exch def
  74.                 /QDisPacked exch def
  75.                 /QDDestHeight exch def
  76.                 /QDDestWidth exch def
  77.                 /Height exch def
  78.                 /Width exch def
  79.                 /QDTop exch def
  80.                 /QDLeft exch def
  81.                 /BitsPerComponent exch def
  82.                 /QDColorTable exch def
  83.                 /QDNumColors exch def
  84.                 /QDPatData exch def
  85.                 /QDPatGrey QDPatData GetPatGrey def
  86.             }
  87.             ifelse
  88.         }
  89.         ifelse
  90.     end
  91. }
  92. def
  93.  
  94. %%%%%%%%%%%%%
  95. %    Name:    bkPat        [0002]
  96. %    Syntax:    qdpat 0 bkPat -
  97. %    About:    Stores the pattern info in the backPattern dict.
  98. %%%%%%%%%%%%%
  99. /bkPat
  100.     {backPattern FillQDPatDict}
  101. def
  102.  
  103. %%%%%%%%%%%%%
  104. %    Name:    pnPat        [0009]
  105. %    Syntax:    qdpat 0 pnPat -
  106. %    About:    Stores the pattern info in the penPattern dict.
  107. %%%%%%%%%%%%%
  108. /pnPat
  109.     {penPattern FillQDPatDict}
  110. def
  111.  
  112. %%%%%%%%%%%%%
  113. %    Name:    fillPat        [000A]
  114. %    Syntax:    qdpat 0 fillPat -
  115. %    About:    Stores the pattern info in the fillPattern dict.
  116. %%%%%%%%%%%%%
  117. /fillPat
  118.     {fillPattern FillQDPatDict}
  119. def
  120.  
  121. %%%%%%%%%%%%%
  122. %    Name:    bkPixPat    [0012]
  123. %    Syntax:    pict2pat bkPixPat -
  124. %    About:    Stores the pattern info in the backPattern dict.
  125. %%%%%%%%%%%%%
  126. /bkPixPat
  127.     {backPattern FillQDPatDict}
  128. def
  129.  
  130. %%%%%%%%%%%%%
  131. %    Name:    pnPixPat    [0013]
  132. %    Syntax:    pict2pat pnPixPat -
  133. %    About:    Stores the pattern info in the penPattern dict.
  134. %%%%%%%%%%%%%
  135. /pnPixPat
  136.     {penPattern FillQDPatDict}
  137. def
  138.  
  139. %%%%%%%%%%%%%
  140. %    Name:    fillPixPat    [0014]
  141. %    Syntax:    pict2pat fillPixPat -
  142. %    About:    Stores the pattern info in the fillPattern dict.
  143. %%%%%%%%%%%%%
  144. /fillPixPat
  145.     {fillPattern FillQDPatDict}
  146. def
  147.  
  148. %END Patterns
  149.